package com.exam.pinduoduo;

import java.util.Arrays;
import java.util.Scanner;

/**
 * date:
 * description:
 */
public class Solution003 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        if(N < M){
            System.out.println(-1);
            return;
        }
        int[][] attacker = new int[N][2];
        for (int i = 0; i < N; i++) {
            attacker[i][0] = scanner.nextInt();
            attacker[i][1] = scanner.nextInt();
        }
        int[][] defender = new int[M][2];
        for (int i = 0; i < M; i++) {
            defender[i][0] = scanner.nextInt();
            defender[i][1] = scanner.nextInt();
        }
        Arrays.sort(attacker, (a1, a2) -> a1[0] == a2[0] ? a2[1] - a1[1] : a2[0] - a1[0]);
        Arrays.sort(defender, (a1, a2) -> a1[1] == a2[1] ? a2[0] - a1[0] : a2[1] - a1[1]);
        int count = 0;
        for (int i = 0; i < M; i++) {
            if(attacker[i][0] < defender[i][1]){
                System.out.println(-1);
                return;
            }else{
                if(attacker[i][1] > defender[i][0]){
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}
